<template>
  <div class="categortitletwostyle">
    <!-- 标题 -->
    <h2>{{ datas.text }}</h2>
    <el-form label-width="80px" :model="datas" size="small">
      <h5 style="color: #000; font-size: 14px">添加图片</h5>
      <!-- 图片广告 -->
      <div v-if="datas.imageList[0]">
        <vuedraggable v-bind="dragOptions">
          <transition-group>
            <section v-for="(item, index) in datas.imageList" :key="item + index" class="imgBanner">
              <i class="el-icon-circle-close" @click="deleteimg(index)" />
              <!-- 图片 -->
              <div class="imag">
                <img :src="item.src" @click="showUpload('second', index)" alt draggable="false"/>
              </div>
            </section>
          </transition-group>
        </vuedraggable>
      </div>
      <!-- 上传图片 -->
      <el-button class="uploadImg" v-if="datas.imageList.length == 0" type="primary" plain @click="showUpload('first')">
        <i class="el-icon-plus" />点击添加图片
      </el-button>

      <div style="height: 10px" />

      <!-- 图片倒角 -->
      <el-form-item label="图片倒角" class="lef borrediu">
        <el-slider v-model="datas.borderRadius" :max="30" input-size="mini" show-input />
      </el-form-item>
    </el-form>
    <!-- 上传图片 -->
    <uploadimg ref="upload" @uploadInformation="uploadInformation" />
  </div>
</template>
<script>
import vuedraggable from "vuedraggable"; // 拖拽组件
import uploadimg from "../../uploadImg"; // 图片上传
export default {
  name: "Categortitletwostyle",
  components: { vuedraggable, uploadimg },
  props: {
    datas: Object,
  },
  data() {
    return {
      dragOptions: {
        animation: 200,
      },
    };
  },
  methods: {
    showUpload() {
      this.$refs.upload.showUpload();
    },
    // 提交
    uploadInformation(res) {
      this.datas.imageList.push({
        src: res,
        text: "",
      });
    },
    /* 删除图片 */
    deleteimg(index) {
      this.datas.imageList.splice(index, 1);
    },
  },
};
</script>
<style lang="scss">
.categortitletwostyle {
  .bor {
    height: 1px;
    margin: 20px 0;
    background-color: #ebedf0;
  }
  /* 标题 */
  h2 {
    padding: 24px 16px 24px 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #f2f4f6;
    font-size: 18px;
    font-weight: 600;
    color: #323233;
  }

  .lef {
    .el-form-item__label {
      text-align: left;
    }
    p {
      line-height: 4px;
    }
  }

  /* 圆角 */
  .borrediu {
    span {
      display: inline-block;
      width: 48px;
      height: 26px;
      text-align: center;
      line-height: 26px;
      color: #979797;
      cursor: pointer;
      transition: all 0.5s;

      &:hover {
        color: #155bd4;
      }

      &.active {
        color: #155bd4;
      }
    }
  }

  /* 图片广告列表 */
  .imgBanner {
    padding: 6px 12px;
    margin: 16px 7px;
    border-radius: 2px;
    background-color: #fff;
    box-shadow: 0 0 4px 0 rgba(10, 42, 97, 0.2);
    display: flex;
    position: relative;

    /* 删除图标 */
    .el-icon-circle-close {
      position: absolute;
      right: -10px;
      top: -10px;
      cursor: pointer;
      font-size: 19px;
    }

    /* 图片 */
    .imag {
      width: 60px;
      height: 60px;
      border-radius: 5px;
      overflow: hidden;
      position: relative;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
        display: inline-block;
      }
    }
  }
}
</style>
